<template>
  <div class="HuikuiInfo el-card is-always-shadow el-card__body">
    <el-dialog
      title="回馈预览"
      :visible.sync="dialogVisible"
      @close="closed"
      width="950px">
      <avue-crud
        ref="crud"
        :option="optionTable"
        :data="listTable">
        <template slot="menuLeft">
          SC系统数据对比与回馈
        </template>
        <template slot-scope="scope" slot="replySaleMoney">
          <el-input-number disabled v-model="formData.replySaleMoney" controls-position="right" :precision="2"></el-input-number>
        </template>
        <template slot-scope="scope" slot="replyRechargeMoney">
          <el-input-number disabled v-model="formData.replyRechargeMoney" controls-position="right" :precision="2"></el-input-number>
        </template>
        <template slot-scope="scope" slot="replyErrorReturnMoney">
          <el-input-number disabled v-model="formData.replyErrorReturnMoney" controls-position="right" :precision="2"></el-input-number>
        </template>
      </avue-crud><br/><br/><br/>
      <avue-form :disabled="isReload" :option="option" v-model="formData" @submit="handleSubmit">
        <template  slot="jdReplyReason" slot-scope="scope">
          <el-select disabled v-model="formData.jdReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in jdReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="kyReplyReason">
          <el-select :disabled="showType==2" v-model="kyReplyReason" placeholder="请选择" style="width: 150px">
            <el-option
              v-for="(item,index) in kyReplyReasonList"
              :key="index"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="menuForm" >
          <el-button v-if="showType==1" type="primary" @click="handleSubmit" >保存</el-button>
          <el-button @click="closed" >返回</el-button>
        </template>
      </avue-form>
    </el-dialog>
  </div>
</template>


<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import ExportJsonExcel from "js-export-excel";
  import {
    fenExYuangettoFixed,
    fenExYuangettoFixed2,
    getSysDictItemListToDict
  } from "../../../../api/subwayRat/commonCheck";
  import {updateSwAuConductorToBeChecked} from "../../../../api/stationTiecketManager/shuJuXieChaGuanLi/BOM/shouPiaoYuanPKCYXC";
  import ElInput from "../../../../../node_modules/element-ui/packages/input/src/input";
  export default {
    components:{
      ElInput
    },
    data() {
      return {
        kyReplyReason :'',
        replySaleMoney:0,
        replyRechargeMoney:0,
        replyErrorReturnMoney:0,
        optionTable:{},
        listTable:[],
        option:{},
        showType : 0, //1编辑，2预览
        isReload:true,
        dialogVisible:true,
        formData:{},
        jdReplyReasonList:[],
        kyReplyReasonList:[]
      }
    },
    created() {
      this.showType = this.$parent.showType;
      getSysDictItemListToDict({"type":"KY_REPLY_REASON"}).then((response)=>{
        this.kyReplyReasonList = response.data.data;
      });
      getSysDictItemListToDict({"type":"JD_REPLY_REASON"}).then((response)=>{
        this.jdReplyReasonList = response.data.data;
      });
    },
    methods: {
      handleSubmit(){
        if(''==this.kyReplyReason){
          this.$message.warning("请选择回馈原因后提交！");
          return
        }
        let p = {
          id:this.formData.id,
          kyReplyReason:this.kyReplyReason,
          kyReplyDetail:this.formData.kyReplyDetail,
          replySaleMoney:Number(this.formData.replySaleMoney)?Number(this.formData.replySaleMoney)*100:'0',
          replyRechargeMoney:Number(this.formData.replyRechargeMoney)?Number(this.formData.replyRechargeMoney)*100:'0',
          replyErrorReturnMoney:Number(this.formData.replyErrorReturnMoney)?Number(this.formData.replyErrorReturnMoney)*100:'0',
        };
        updateSwAuConductorToBeChecked(p).then((response)=>{
          if(response.data.code==0){
            this.$message.success("操作成功");
            this.$parent.getList();
          }else{
            this.$message.success("操作失败");
          }

        });
        this.$parent.getList();
        this.closed();
      },
      recallShow(row){
        this.kyReplyReason = row.kyReplyReason;
        Object.assign(this.formData,row);
        this.formData.replySaleMoney=fenExYuangettoFixed2(this.formData.replySaleMoney);
        this.formData.replyRechargeMoney=fenExYuangettoFixed2(this.formData.replyRechargeMoney);
        this.formData.replyErrorReturnMoney=fenExYuangettoFixed2(this.formData.replyErrorReturnMoney);
        this.listTable.push(row);
        if(1==this.showType){
          this.option.group[0].column[6].disabled = false;
        }
      },
      closed(){
        this.dialogVisible=false;
        this.$parent.isShowDia=false;
      },
      getOption(){
        if(1 == this.$parent.showType) {
          this.isReload = false;
        }
        this.optionTable = {
          border: false,
          index: false,
          indexLabel: '序号',
          stripe: false,
          menuAlign: 'center',
          menu: false,
          viewBtn: false,
          editBtn: false,
          emptyBtn:false,
          delBtn: false,
          align: 'center',
          addBtn: false,
          column: [{
            label: '回馈售票金额',
            prop: 'replySaleMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replySaleMoney');
            },
            slot:true,
            search: false,
            hide: false,
            disabled:true
          },{
            label: '回馈充值金额',
            prop: 'replyRechargeMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyRechargeMoney');
            },
            slot:true,
            search: false,
            hide: false,
            disabled:true
          },{
            label: '回馈补票金额',
            prop: 'replyErrorReturnMoney',
            formatter:function (row,value , label, column) {
              return fenExYuangettoFixed(row,'replyErrorReturnMoney');
            },
            slot:true,
            search: false,
            hide: false,
            disabled:true
          }]
        };
        this.option={
          submitBtn:false,
          emptyBtn:false,
          group:[{
              icon:'',
              label: '',
              // collapse:false,
              prop: 'group',
              column: [{
                label: '售票员',
                prop: 'conductorPersonName',
                disabled:true,
                labelWidth:130
              },{
                label: '员工号',
                prop: 'conductorPersonCode',
                disabled:true,
                labelWidth:130
              },{
                label: '收入日期',
                prop: 'recordTime',
                disabled:true,
                labelWidth:130
              },
              //   {
              //   label: '差异金额',
              //   prop: 'differenceAmount',
              //   disabled:true,
              //   labelWidth:130,
              //   formatter:function (row,value , label, column) {
              //     return fenExYuangettoFixed(row,'differenceAmount');
              //   }
              // },
                {
                label: '机电专业回馈差异原因',
                prop: 'jdReplyReason',
                formslot : true,
                labelWidth:130
              },{
                label: '客运专业回馈差异原因',
                prop: 'kyReplyReason',
                formslot : true,
                labelWidth:130
              },{
                label: '机电专业详细描述',
                prop: 'jdReplyDetail',
                disabled : true,
                type:'textarea',
                labelWidth:130
              },{
                label: '客运专业详细描述',
                prop: 'kyReplyDetail',
                disabled : true,
                type:'textarea',
                labelWidth:130
              }]
            }]
        }
      }
    },
    mounted() {
      this.getOption();
    }
  }
</script>
